function [y,e,A,B]=ad_sinus(x,fo,fs)
%
%single frequency adjustment - least squares - known fo
%
% Input: x - data
%        fo - frequency of interest 
%        fs - sampling frequency
%
% Output: y - Best adjusted data
%         e - errors
%         A,B - cos/sine coefficients
%
n=length(x);x=x(:);
uc=cos(2*pi*(0:n-1)*fo/fs);
us=sin(2*pi*(0:n-1)*fo/fs);
v=[uc*x;
   us*x];
V=[uc*uc' uc*us';us*uc' us*us'];
r=pinv(V)*v;
A=r(1);
B=r(2);
y=[uc' us']*r;
e=x-y;

